/*
function print(s) 
输出:
    1  
   212 
  32123
 4321234
543212345
*/
const res = require("express/lib/response");

function print(n) {
  const result = new Array(n).fill('').map((_, i) => {
    const line = new Array(2*n -1).fill(' ')
    line[n -1] = 1;
    for(let j = 1; j <= i+1 ; j++) {
      line[n - j] = j;  // 左 n-1 - j + 1
      line[n + j-2] = j; // n 0 -1 + j - 1
    }
    return line.join('');
  }).join('\n')
  console.log(result)
}
// print(5)

// 输出半金字塔
function printHalf(n) {
  const result = new Array(n).fill('').map((_, i) => {
    let line = new Array(n + Math.abs(n-1)).fill(' ')
    line[0] = 1;
    let count = 2;
    for(let j = 2, len = 2 * i + 1; j <= len; j+=2 ) {
      line[j] = count; 
      count++;
    }
    return line.join('')
  }).join('\n')
  console.log(result);
}
printHalf(5)

// 帕斯卡三角形 / 杨慧三角型
/*
          1
        1   1
      1   2   1
    1   3   3    1
  1  4    6   4   1
1  5   10   10  5   1
*/ 
function printPascal(n) {
  const result = new Array(n).fill('').map((_, i) => {
    const line = new Array(2* n -1).fill(' ');
    
    return line;
  })
  console.log(result)
}